import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
import {isAuth} from '../utils/auth'



Vue.use(VueRouter)

let router= new VueRouter({
    mode:'history',
    routes
})

//全局前置守卫
router.beforeEach((to, from, next) => {

    let isLogined = isAuth()

    if (to.path === '/login') {
        if (isLogined) {

            next('/')
        } else {
            next()
        }
    } else {
        if (isLogined) {
            next()
        } else {
            if( to.path==='/Register'){
                next()
            }else{
                next('/login')
            }
            
        }
    }
})


export default router